package com.example.h3x.androidmalware.View.Fragments;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.h3x.androidmalware.View.Tabs.MonitoringCameraFragment;
import com.example.h3x.androidmalware.View.Tabs.MonitoringMicFragment;
import com.example.h3x.androidmalware.R;



public class MonitoringFragment extends Fragment {




    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View v = inflater.inflate(R.layout.fragment_monitoring, container, false);
        ViewPager mPager =  v.findViewById(R.id.pager);
        TabLayout mTabLayout =  v.findViewById(R.id.tab_layout);

        mPager.setAdapter(new TabsAdapter(getChildFragmentManager()));
        mTabLayout.setupWithViewPager(mPager);

        setHasOptionsMenu(true);

        return v;
    }


    class TabsAdapter extends FragmentPagerAdapter {

        private TabsAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return 2;
        }

        @Override
        public Fragment getItem(int i) {
            switch (i) {
                case 0:
                    return new MonitoringCameraFragment();
                case 1:
                    return new MonitoringMicFragment();
            }
            return null;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
                case 0:
                    return "Camera";
                case 1:
                    return "Mic";
            }
            return "";
        }
    }

}
